package com.zmn.oms.third.gomegj;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.springframework.stereotype.Component;

/**
 * 类描述：国美管家接口使用的常量类
 *
 * @author xiewenbing
 * @date 2020/11/04 16:00
 */
@Component
public class GmgjConsts {

    /**
     * 国美管家渠道名称
     */
    public static final String CHANNEL_NAME = "平台渠道E10/E33（国美管家-家电维修,宅修）";

    /**
     * 渠道对接开关
     */
    public static boolean POWER_ON = false;

    /**
     * app id
     */
    public static String APP_ID = "5ZWE5pyo6bif";

    /**
     * app secret
     */
    public static String APP_SECRET = "272ee20ce96546cc921d85a153412352";

    /**
     * 用户名
     */
    public static String APP_USERNAME = "zuomuniao";

    /**
     * 密码
     */
    public static String APP_PASSWORD = "zuomuniao";

    /**
     * API URL
     */
    public static String API_URL = "http://azd.dev.gomegj.com/";

    /**
     * 支付URL
     */
    public static String PAY_URL = "http://wapgjdev.m.gome.com.cn/wxpay/v1/sod/getVQCodeUrl?orderId=%s&orderType=1";

    /**
     * 获取token url path
     */
    public static final String PATH_GET_TOKEN = "/oauth2/accessToken?client_id=%s&grant_type=access_token&username=%s&password=%s&timestamp=%s&sign=%s";

    /**
     * 刷新token url path
     */
    public static final String PATH_REFRESH_TOKEN = "/oauth2/refreshToken?client_id=%s&client_secret=%s&refresh_token=%s";

    /**
     * 订单审核 PATH
     */
    public static final String PATH_AUDIT_ORDER = "/platform/audit?token=%s";

    /**
     * 订单派单同步 PATH
     */
    public static final String PATH_ORDER_DISTRIBUTE = "/platform/dispatchWorker?token=%s";

    /**
     * 订单完成 PATH
     */
    public static final String PATH_ORDER_FINISH = "/platform/complate?token=%s";

    /**
     * 订单取消 PATH
     */
    public static final String PATH_ORDER_CANCEL = "/platform/cannel?token=%s";

    /**
     * 订单改预约 PATH
     */
    public static final String PATH_ORDER_MODIFY_DUTYTIME = "/platform/modifyTime?token=%s";

    /**
     * 获取订单详情 PATH
     */
    public static final String PATH_GET_ORDER_DETAIL = "/platform/findOrder?token=%s";

    /**
     * 订单服务项 PATH
     */
    public static final String PATH_ORDER_SERVICE = "/platform/changeOrderDetail?token=%s";

    /**
     * 获取订单列表 PATH
     */
    public static final String PATH_GET_ORDER_LIST = "/platform/searchOrderList?token=%s";

    /**
     * 交互应答码 - 成功
     */
    public static final int RESPONSE_CODE_SUCCESS = 200;

    /**
     * 交互应答码 - 系统错误
     */
    public static final int RESPONSE_CODE_SYSTEM_ERROR = 500;

    /**
     * 交互应答码 - 数据验证错误
     */
    public static final int RESPONSE_CODE_VALIDATE_ERROR = 501;

    /**
     * 交互应答码 - 订单不存在
     */
    public static final int RESPONSE_CODE_ORDER_NO_EXIST = 502;

    /**
     * 交互应答码 - 订单异常
     */
    public static final int RESPONSE_CODE_ORDER_ABNORMAL = 503;

    /**
     * 交互应答码 - token失效
     */
    public static final int RESPONSE_CODE_TOKEN_INVALID = 504;

    /**
     * 订单消息之方法-创建订单
     */
    public static final String METHOD_CREATE_ORDER = "order";

    /**
     * 订单消息之方法-取消订单
     */
    public static final String METHOD_CANCEL_ORDER = "cannel";

    /**
     * 订单消息之方法-支付订单
     */
    public static final String METHOD_PAY_ORDER = "pay";

    /**
     * 订单消息之方法-改预约
     */
    public static final String METHOD_MODIFY_TIME = "modifyTime";

    /**
     * 获取最大的页面数
     */
    public static final int MAX_PAGE_COUNT = 10;

    /**
     * 获取最大的页记录
     */
    public static final int MAX_PAGE_SIZE = 100;

    /**
     * 订单类型 1-维修
     */
    public static final int ORDER_BUSSION_TYPE_REPAIR = 1;

    /**
     * 订单支付状态 1-已支付
     */
    public static final int ORDER_PAY_TYPE_DONE = 1;


    /**
     * 渠道师傅固定电话
     */
    public final static String MASTER_PHONE = "13350300176";

    /**
     * 师傅缺省填入
     */
    public final static String MASTER_DEFAULT_NAME = "啄木鸟师傅";

    /**
     * 维修类型-保外
     */
    public final static String REPAIR_TYPE_OUT_INSURE = "OUT_INSURE";

    /**
     * 维修类型-家居家电
     */
    public final static String REPAIR_TYPE_HYDROPOWER = "HYDROPOWER";


    public final static String TEST_SIGN = "TestSign132546";
    /**
     * 通过返回码获取对应的消息
     *
     * @param code
     * @return
     */
    public static String getErrorMsg(int code) {

        String errMsg = "系统处理失败";
        switch (code) {
            case RESPONSE_CODE_SUCCESS:
                errMsg = "成功";
                break;
            case RESPONSE_CODE_SYSTEM_ERROR:
                errMsg = "系统错误";
                break;
            case RESPONSE_CODE_VALIDATE_ERROR:
                errMsg = "数据验证失败";
                break;
            case RESPONSE_CODE_ORDER_NO_EXIST:
                errMsg = "订单不存在";
                break;
            case RESPONSE_CODE_ORDER_ABNORMAL:
                errMsg = "订单状态异常";
                break;
            case RESPONSE_CODE_TOKEN_INVALID:
                errMsg = "token失效";
                break;
        }

        return errMsg;
    }

    @NacosValue(value = "${gmgj.service.power-on:false}", autoRefreshed = true)
    public void setPowerOn(boolean powerOn) {
        POWER_ON = powerOn;
    }

    @NacosValue(value = "${gmgj.service.appId:5ZWE5pyo6bif}", autoRefreshed = true)
    public void setAppId(String appId) {
        APP_ID = appId;
    }

    @NacosValue(value = "${gmgj.service.appSecret:272ee20ce96546cc921d85a153412352}", autoRefreshed = true)
    public void setAppSecret(String appSecret) {
        APP_SECRET = appSecret;
    }

    @NacosValue(value = "${gmgj.service.userName:zuomuniao}", autoRefreshed = true)
    public void setAppUsername(String userName) {
        APP_USERNAME = userName;
    }

    @NacosValue(value = "${gmgj.service.password:zuomuniao}", autoRefreshed = true)
    public void setAppPassword(String password) {
        APP_PASSWORD = password;
    }

    @NacosValue(value = "${gmgj.service.apiUrl:http://azd.dev.gomegj.com/}", autoRefreshed = true)
    public void setAppUrl(String apiUrl) {
        API_URL = apiUrl;
    }

    @NacosValue(value = "${gmgj.service.payUrl:http://wapgjdev.m.gome.com.cn/wxpay/v1/sod/getVQCodeUrl?orderId=%s&orderType=1}", autoRefreshed = true)
    public void setPayUrl(String payUrl) {
        PAY_URL = payUrl;
    }
}
